/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CustomerInfo;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerFieldManager;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.db.DealFieldManager;
/*     */ import com.newcrm.db.UserManager;
/*     */ import com.newcrm.db.VOIPCallManager;
/*     */ import com.newcrm.exception.DBException;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import javax.servlet.RequestDispatcher;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class ShowCompany extends AbstractAction
/*     */ {
/*  37 */   private static Logger logger = Logger.getLogger(ShowCompany.class.getName());
/*     */ 
/*  39 */   protected int id = 0;
/*     */ 
/*     */   public ShowCompany(AbstractHttpServlet servlet, String id) {
/*  42 */     super(servlet);
/*  43 */     this.id = Util.str2Int(id);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, NotFoundException
/*     */   {
/*  48 */     User user = super.getLoginUser(request);
/*  49 */     CustomerManager manager = new CustomerManager();
/*     */ 
/*  51 */     CustomerInfo customerInfo = null;
/*     */     try {
/*  53 */       customerInfo = manager.getCustomerInfo(this.id, true, true);
/*     */     } catch (DBException e) {
/*  55 */       logger.warn("get company info failed", e);
/*  56 */       throw new NotFoundException();
/*     */     }
/*  58 */     if (customerInfo == null) {
/*  59 */       logger.warn("company is null");
/*  60 */       throw new NotFoundException();
/*     */     }
/*  62 */     if (customerInfo.type != 0) {
/*  63 */       logger.warn("company type is error");
/*  64 */       throw new NotFoundException();
/*     */     }
/*     */ 
/*  67 */     String ip = Util.getClientIpAddr(request);
/*  68 */     logger.warn("ip:" + ip + " / 用户Id：" + user.userId + " /  用户名：" + 
/*  69 */       user.name + ", 浏览了公司：id:  " + customerInfo.id + " / 名称：" + 
/*  70 */       customerInfo.name);
/*     */ 
/*  73 */     String type = Util.getURLParameter(request.getParameter("type"));
/*     */ 
/*  76 */     if (!customerInfo.hasViewRight(user, super.getCompany(user.companyId))) {
/*  77 */       if ("json".equals(type)) {
/*  78 */         showErrorMessage(response, "您没有查看该客户的权限");
/*  79 */         return;
/*     */       }
/*     */ 
/*  82 */       request.getRequestDispatcher("/nopermission.jsp").forward(
/*  83 */         request, response);
/*  84 */       return;
/*     */     }
/*     */ 
/*  88 */     UserManager userManager = new UserManager();
/*     */     try
/*     */     {
/*  91 */       userManager.addViewCustomerId(user.userId, 
/*  92 */         String.valueOf(customerInfo.id));
/*     */     } catch (DBException e) {
/*  94 */       logger.warn("add user view customer ids failed", e);
/*     */     } catch (SQLException e) {
/*  96 */       logger.warn("add user view customer ids failed", e);
/*     */     }
/*     */ 
/* 100 */     List peoples = new ArrayList();
/*     */     try {
/* 102 */       peoples = manager.getPeoples(customerInfo.id);
/*     */     } catch (Exception e) {
/* 104 */       logger.warn("get company peoples failed", e);
/*     */     }
/*     */ 
/* 108 */     if ("json".equals(type)) {
/* 109 */       response.setContentType("text/html;charset=utf-8");
/* 110 */       PrintWriter out = response.getWriter();
/* 111 */       JSONObject jsonObject = new JSONObject();
/* 112 */       jsonObject.put("error", "0");
/* 113 */       jsonObject.put("customerInfo", customerInfo);
/* 114 */       jsonObject.put("peoples", peoples);
/* 115 */       out.println(jsonObject);
/* 116 */       out.flush();
/* 117 */       out.close();
/* 118 */       return;
/*     */     }
/*     */ 
/* 121 */     CustomerFieldManager manager2 = new CustomerFieldManager();
/*     */ 
/* 123 */     DealFieldManager dealFieldManager = new DealFieldManager();
/*     */     try {
/* 125 */       List fields = manager2.list(user.companyId, 
/* 126 */         1);
/* 127 */       request.setAttribute("fields", fields);
/*     */ 
/* 129 */       List dealFields = dealFieldManager
/* 130 */         .list(user.companyId);
/* 131 */       request.setAttribute("dealFields", dealFields);
/*     */     } catch (Exception e) {
/* 133 */       logger.warn("get company customer field info failed", e);
/*     */     }
/*     */ 
/* 136 */     String duplicate = request.getParameter("duplicate");
/* 137 */     request.setAttribute("duplicate", duplicate);
/* 138 */     request.setAttribute("customerInfo", customerInfo);
/* 139 */     request.setAttribute("peoples", peoples);
/*     */ 
/* 142 */     request.setAttribute("merge", request.getParameter("merge"));
/* 143 */     request.setAttribute("oldName", 
/* 144 */       Util.getURLParameter(request.getParameter("oldName")));
/*     */ 
/* 147 */     VOIPCallManager voipCallManager = new VOIPCallManager();
/* 148 */     Date syncTime = voipCallManager.getLastSynchronousTime(user.companyId);
/* 149 */     request.setAttribute("syncTime", syncTime);
/*     */ 
/* 151 */     request.getRequestDispatcher("/company_detail.jsp").forward(request, 
/* 152 */       response);
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ShowCompany
 * JD-Core Version:    0.6.1
 */